import {FunctionDecoratorType} from "./types";
import {getMethodName} from "./shared";

//必要性验证
export const requiredVerify: FunctionDecoratorType = {
  type: 'required',
  verifyFun(paramList: number[], target: Object, propertyKey: string | symbol, argumentList: IArguments) {
    const argumentsLength = argumentList.length;
    let noProblem = true;
    for (let i = 0; i < paramList.length; i++) {
      const paramIndex = paramList[i];
      if (paramIndex > argumentsLength || argumentList[paramIndex] === undefined || argumentList[paramIndex] === null) {
        console.error(`${getMethodName(target, propertyKey)}，第${paramIndex + 1}个参数是必须的！`);
        noProblem = false;
      }
    }
    throw "参数必要性验证失败"
  }
}